package com.ArrayQueue;

import java.util.Scanner;

public class ArrayQueueDemo {
    public static void main(String[] args) {
        //测试用数组模拟队列
        ArrayQueue arrayQueue = new ArrayQueue(3);
        //接收用户输入
        int key = 0;
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;
        while(loop){
            System.out.println("1:显示队列");
            System.out.println("2:添加数据到队列");
            System.out.println("3:取出队列数据");
            System.out.println("4:获取队列头部数据");
            System.out.println("5:查看队尾首指针位置");
            System.out.println("6:退出程序");
            key = scanner.nextInt();
            switch (key){
                case 1:
                    arrayQueue.showQueue();
                    break;
                case 2:
                    System.out.print("请输入要添加的数据：");
                    int value = scanner.nextInt();
                    arrayQueue.addQueue(value);
                    break;
                case 3:
                    //队列为空时会抛出异常。通过try-catch处理

                    try {
                        int res = arrayQueue.getQueue();
                        System.out.println(res+"已从队列中取出");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 4:
                    try {
                        int data = arrayQueue.getHandData();
                        System.out.println("队列首部元素为："+data);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 5:
                    arrayQueue.showRearAndFront();
                    break;
                case 6:
                    //退出循环时关闭scanner
                    scanner.close();
                    loop =false;
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序已退出");

    }




}
